# -*- coding: utf-8 -*-

from django.shortcuts import render_to_response
from django.contrib import auth
from django.http import HttpResponseRedirect, HttpResponse
from django.template import RequestContext
import settings

def book(request):
    a = 5
    if a == 1:
        return render_to_response('book.html', {'can_list_users': True, 'books': [
        {'title': 'title1', 'authors': ['author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author2','author1','author2','author1'], 'url': '/?'},
        {'title': 'title2', 'authors': ['author3', 'author4'], 'url': '/?'}]}, context_instance=RequestContext(request))
    if a == 2:
        return render_to_response('bookcopies.html', {'can_list_users': True, 'book': {'locations': ['location1', 'location2', 'locdasdation3'], 'title': 'title', 'authors': ['author3', 'author4'], 'items': [{'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb'},
    {'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb'}
    ,{'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb'},
    {'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsdjksdbsu odcoinsdoifndsfisdofnasdasdasdasdassdfusduifb'},
    {'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsdjksdbsu odcoinsdoifndsfisdofnasdasdasdasdassdfusduifb'},
    {'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsbbbbbbbbbbbbbdscuibsdjksdbsuodcoinsdoifndsfisdofnasdasdasdasdassdfusduifb'}]}}, context_instance=RequestContext(request))
    if a == 3:
        return render_to_response('bookcopy.html', {'from': '10-03-2010', 'to': '11-05-2011', 'rental_possible': True, 'can_reserve': True, 'can_rent': True, 'can_return': True, 'can_list_users': True, 'book': {'title': 'title1', 'authors': ['author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author2','author1','author2','author1'],
    'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbbb bbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbb bbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusuifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbb bbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb', 
    'picture_url': settings.MEDIA_URL + 'pictures/cat.gif'}}, context_instance=RequestContext(request))
    if a == 4:
        return render_to_response('rental.html', {'from': '10-03-2010', 'to': '11-05-2011', 'rental_possible': True, 'can_reserve': True, 'can_rent': True, 'can_list_users': True, 'book': {'title': 'title1', 'authors': ['author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author2','author1','author2','author1'],
    'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbbb bbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbb bbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusuifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbb bbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb', 
    'picture_url': settings.MEDIA_URL + 'pictures/cat.gif'}}, context_instance=RequestContext(request))
    if a == 5:
        return render_to_response('reservation.html', {'from': '10-03-2010', 'to': '11-05-2011', 'rental_possible': True, 'can_reserve': True, 'can_rent': True, 'can_list_users': True, 'book': {'title': 'title1', 'authors': ['author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author1', 'author2','author2','author1','author2','author1'],
    'url': '?', 'location': 'location', 'state': 'state', 'publisher': 'publisher', 'year': 2009, 'description': 'sdjkfbdsibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbbb bbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbb bbbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusuifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbbbb bbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbbb bbbbbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdbbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsbbbdscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb sdjkfbdsscuibsd jksdbsuodc oinsdoifndsfisdofn sdfusduifb', 
    'picture_url': settings.MEDIA_URL + 'pictures/cat.gif'}}, context_instance=RequestContext(request))
    if a==6:
        return render_to_response('reserve.html', {'book': {'title': 'aaaaa sd dfsd'}},context_instance=RequestContext(request))
    if a==7:
        return render_to_response('user.html', {'user': {'name': 'aaaaa', 'surname': 'asdasd', 'mail': 'aaa@wp.pl'}},context_instance=RequestContext(request))
    if a==8:
        return render_to_response('users.html', {'users': [{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'},{'name': 'aaaaa', 'surname': 'asdasd', 'url': '?'}]},context_instance=RequestContext(request))
def login(request):
    if request.user.is_authenticated():
        return render_to_response('entelib.html',{'can_list_users': True},context_instance=RequestContext(request))
    else:
        query = request.POST.get('username', '')
        if query:
            username = request.POST['username']
            password = request.POST['password']
            user = auth.authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                return render_to_response('entelib.html',{'can_list_users': True},context_instance=RequestContext(request))
            else:
                return render_to_response('login.html',{'can_list_users': True},context_instance=RequestContext(request))
        else:
            return render_to_response('login.html',{'can_list_users': True},context_instance=RequestContext(request))
            
def logout(request):
    if request.user.is_authenticated():
        auth.logout(request)
        return HttpResponseRedirect('/entelib/')
    else:
        return HttpResponseRedirect('/entelib/')
